package com.wenan.ui.grids
{
	import flash.display.Sprite;
	
	import mx.controls.DataGrid;
	
	public class DataReportGrid extends DataGrid
	{
		private var _rowColorFunction:Function;   //用于在外部能通过指定一个方法 去实现改变列的背景色 
		
		public function DataReportGrid()
		{
			super();
			
			setStyle("paddingLeft", "0");
			setStyle("paddingTop", "0");
			setStyle("paddingRight", "0");
			setStyle("paddingBottom", "1");
			setStyle("contentBackgroundColor", "#000000");
			setStyle("rollOverColor", "#000000");
			setStyle("focusColor", "#000000");
		}
		
		public function get rowColorFunction():Function
		{
			return _rowColorFunction;
		} 
		
		public function set rowColorFunction(f:Function):void
		{
			this._rowColorFunction = f;
		}
		
		//复写该方法
		override protected function drawRowBackground(s:Sprite,rowIndex:int,y:Number, height:Number, color:uint, dataIndex:int):void
		{
			if (dataProvider)
			{
				var usedRowColorFunction:Function = _rowColorFunction;
				if(usedRowColorFunction == null ){
					usedRowColorFunction = defaultColorFunction;
				}
				if( dataIndex < this.dataProvider.length ){
					var item:Object = this.dataProvider.getItemAt(dataIndex);
					color = usedRowColorFunction.call(this, item, color);
				}      	
			} 
			super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
		} 
		
		private function defaultColorFunction(item:Object, color:uint):uint
		{
			return 0x000000;
		} 
	}
}